package com.ruoyi.violate.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.violate.domain.ViolateTilte;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.violate.domain.ViolateTypeShop;
import com.ruoyi.violate.service.IViolateTypeShopService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 同类型店铺Controller
 * 
 * @author ruoyi
 * @date 2023-04-29
 */
@RestController
@RequestMapping("/violate/typeShop")
public class ViolateTypeShopController extends BaseController
{
    @Autowired
    private IViolateTypeShopService violateTypeShopService;

    /**
     * 查询同类型店铺列表
     */
    @PreAuthorize("@ss.hasPermi('violate:typeShop:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViolateTypeShop violateTypeShop)
    {
        startPage();
        List<ViolateTypeShop> list = violateTypeShopService.selectViolateTypeShopList(violateTypeShop);
        return getDataTable(list);
    }

    /**
     * 查询shopNames
     */
    @GetMapping("/listShopName")
    public TableDataInfo listShopName()
    {
        List<String> ShopName = violateTypeShopService.selectViolateTypeShopNames();

        return getDataTable(ShopName);
    }

    /**
     * 导出同类型店铺列表
     */
    @PreAuthorize("@ss.hasPermi('violate:typeShop:export')")
    @Log(title = "同类型店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViolateTypeShop violateTypeShop)
    {
        List<ViolateTypeShop> list = violateTypeShopService.selectViolateTypeShopList(violateTypeShop);
        ExcelUtil<ViolateTypeShop> util = new ExcelUtil<ViolateTypeShop>(ViolateTypeShop.class);
        util.exportExcel(response, list, "同类型店铺数据");
    }

    /**
     * 获取同类型店铺详细信息
     */
    @PreAuthorize("@ss.hasPermi('violate:typeShop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(violateTypeShopService.selectViolateTypeShopById(id));
    }

    /**
     * 新增同类型店铺
     */
    @PreAuthorize("@ss.hasPermi('violate:typeShop:add')")
    @Log(title = "同类型店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViolateTypeShop violateTypeShop)
    {
        return toAjax(violateTypeShopService.insertViolateTypeShop(violateTypeShop));
    }

    /**
     * 修改同类型店铺
     */
    @PreAuthorize("@ss.hasPermi('violate:typeShop:edit')")
    @Log(title = "同类型店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViolateTypeShop violateTypeShop)
    {
        return toAjax(violateTypeShopService.updateViolateTypeShop(violateTypeShop));
    }

    /**
     * 删除同类型店铺
     */
    @PreAuthorize("@ss.hasPermi('violate:typeShop:remove')")
    @Log(title = "同类型店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(violateTypeShopService.deleteViolateTypeShopByIds(ids));
    }

    /**
     * 导入数据tilte
     */
    @PreAuthorize("@ss.hasPermi('violate:typeShop:import')")
    @PostMapping("import")
    public AjaxResult importFile(@RequestBody ViolateTypeShop violateTypeShop) throws IOException {
        if(StringUtils.isEmpty(violateTypeShop.getFilePath()))
            return AjaxResult.error("请上传文件");
        return toAjax(violateTypeShopService.importFile(violateTypeShop.getFilePath()));
    }
}
